package cn.ijero.game2048

import cn.ijero.game2048.Number.*
import com.soywiz.korge.view.*
import com.soywiz.korim.color.Colors

class Block(val number: Number) : Container() {
    init {
        roundRect(cellSize, cellSize, 5.0, fill = number.color)
        val textColor = when (number) {
            ZERO, ONE -> {
                Colors.BLACK
            }
            else -> {
                Colors.WHITE
            }
        }
        textOld(number.value.toString(), textSizeFor(number), textColor, font).centerBetween(
            0.0,
            0.0,
            cellSize,
            cellSize
        )
    }

    private fun textSizeFor(number: Number) = when (number) {
        ZERO, ONE, TWO, THREE, FOUR, FIVE -> {
            cellSize * 0.5
        }
        SIX, SEVEN, EIGHT -> {
            cellSize * 0.45
        }
        NINE, TEN, ELEVEN, TWELVE -> {
            cellSize * 0.4
        }
        THIRTEEN, FOURTEEN, FIFTEEN -> {
            cellSize * 0.35
        }
        SIXTEEN -> {
            cellSize * 0.3
        }
    }

}

fun Container.block(number: Number) = Block(number).addTo(this)
